package org.supda.system.util;

import java.sql.Timestamp;
import java.text.DecimalFormat;

import org.springframework.util.StringUtils;

/**
 * 
 * @author supda
 * @Date 2017-2-15 下午5:07:09
 * 
 */
public class CommonUtils {

	/**
	 * 处理$带来的无法正则替换问题
	 * 
	 * @return
	 */
	public static String replaceAll(String source, String regex, String data) {
		source = source.replaceAll(regex, formatData(data));
		return formatDataReserve(source);
	}

	private static String formatData(String data) {
		if (StringUtils.isEmpty(data))
			return "";

		while (data.contains("$")) {
			data = data.replace("$", "{ZF4}");
		}
		return data;
	}

	private static String formatDataReserve(String data) {
		while (data.contains("{ZF4}")) {
			int inx = data.indexOf("{ZF4}");
			data = data.substring(0, inx) + "$"
					+ data.substring(inx + "{ZF4}".length());
		}
		return data;
	}

	public static Timestamp currentTimeStamp() {
		return new Timestamp(System.currentTimeMillis());
	}

}
